﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using NPMonitor.DataModel;
using NPMonitor.Helpers;

namespace NPMonitor.Interfaces
{
    /// <summary>
    /// The interface that needs to be implemented by JobStore providers.
    /// </summary>
    public interface IJobStore2 : IJobStore
    {
        #region Job Operations

        /// <summary>
        /// Creates a new job in the job store.
        /// </summary>
        /// <param name="jobData"></param>
        /// <returns>The job Data Model</returns>
        /// <remarks>
        /// This must cause <see cref="JobActionRequired"/> event to be raised.
        /// </remarks>
        JobData CreateJob(JobData jobData, CalendarSchedule schedule);

        /// <summary>
        /// Create a bunch of jobs in job store
        /// </summary>
        /// <param name="joblist"></param>
        List<JobData> CreateJobs(List<JobData> joblist, CalendarSchedule schedule);
        
        /// <summary>
        /// Get the count of specific job where its status is deleted.
        /// </summary>
        /// <param name="jobId"></param>
        /// <returns>the count of deleted jobs</returns>
        int GetDeletedJobCount(int jobId);

        List<string> GetJobScheduleByID(int id);

        /// <summary>
        /// 根据机器名获取Active Scheduled jobs
        /// </summary>
        /// <param name="nextExecutionStartDateTimeAtOrBefore"></param>
        /// <returns></returns>
        ReadOnlyCollection<JobData> GetJobsByMachineName(string machineName, int pageIndex, int pageSizes, out int total);

        /// <summary>
        /// 根据机器名获取Active Scheduled job的总数
        /// </summary>
        /// <param name="nextExecutionStartDateTimeAtOrBefore"></param>
        /// <returns></returns>
        int GetActiveScheduleJobsTotalCountByMachineName(string machineName);

        List<JobData> GetScheduledTaskById(int taskId);

        #endregion

        void RefreshJobStatus();

        JobExecutionHistory GetJobExecutionHistory(int historyId);

        ReadOnlyCollection<JobExecutionHistory> GetJobExecutionHistories(string machineName, int pageIndex, int pageSizes, string jobName, Nullable<JobStatus> status, DateTime startTime, DateTime endTime, out int total);

        JobData GetTaskInfoById(int id);

        bool SetJobStatuses(long jobId, JobStatus? oldStatus, JobStatus newStatus, string errorMessage = null);
    }
}
